#include "simple_unittest.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iostream> 
#include <exception> 


unittest::unittest(std::string fileName):m_fileName(fileName)
{
}

unittest::~unittest()
{
	std::ifstream statedTestFile( m_fileName.c_str() );

	std::stringstream buffer;
	if ( statedTestFile )
	{
		buffer << statedTestFile.rdbuf();
		statedTestFile.close();
	}

	if(str().empty())
	{
		std::cout << "Test output is empty" << std::endl;
		throw "";
	}

	if(buffer.str() != str())
	{
		std::ofstream newResultFile(std::string(m_fileName + "~").c_str() );
		newResultFile << str();

		newResultFile.close();

		std::cout << "Test file don't match" << std::endl;
		throw "";
	}
	else
	{
		remove(std::string(m_fileName + "~").c_str() );
	}
}


